package com.yunmai11.yunmai.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.yunmai11.yunmai.R;
import com.yunmai11.yunmai.adapter.XRecyclerViewAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/15.
 */
public class HomeFragment extends BaseFragment {
    private XRecyclerView x_rv;
    private XRecyclerViewAdapter mAdapter;
    private List<String> data;

    @Override
    protected View initView() {
        View v = LayoutInflater.from(mContext).inflate(R.layout.home_fragment, null);
        x_rv = (XRecyclerView) v.findViewById(R.id.x_rv);
        return v;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return initView();
    }

    @Override
    protected void initData() {
        super.initData();
        genData();
        mAdapter = new XRecyclerViewAdapter(getActivity(), data);
        x_rv.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.HORIZONTAL));
        x_rv.setAdapter(mAdapter);
        x_rv.setLayoutManager(new LinearLayoutManager(getActivity()));
        x_rv.setPullRefreshEnabled(false);

    }

    private void genData() {
        data = new ArrayList<String>();
        for (int i=0;i<20;i++) {
            data.add("Info-"+i);
        }
    }
}
